public class BubbleSort {
    public static void bubbleSort(int[] arr){
        //趟数
        for (int i = 0; i < arr.length - 1; i++) {
            //一趟
            boolean flg = false;
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]){
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;
                    flg = true;
                }
            }
            if (flg = false){
                return;
            }
        }
    }
    public static void main(String[] args) {
        int[] arr = {1, 5, 2, 4, 6, 8, 9, 3, 10, 7};
        bubbleSort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
